home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue50 / Localise / DataM.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-06-17  |  2.4 KB  |  107 lines

  1. unit DataM;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   DBTables, DB;
  8.  
  9. type
  10.   TDataModule2 = class(TDataModule)
  11.     Table1: TTable;
  12.     DataSource1: TDataSource;
  13.     Table1CustNo: TFloatField;
  14.     Table1Company: TStringField;
  15.     Table1Addr1: TStringField;
  16.     Table1Addr2: TStringField;
  17.     Table1City: TStringField;
  18.     Table1State: TStringField;
  19.     Table1Zip: TStringField;
  20.     Table1Country: TStringField;
  21.     Table1Phone: TStringField;
  22.     Table1FAX: TStringField;
  23.     Table1TaxRate: TFloatField;
  24.     Table1Contact: TStringField;
  25.     Table1LastInvoiceDate: TDateTimeField;
  26.     procedure Table1NewRecord(DataSet: TDataSet);
  27.     procedure Table1BeforeInsert(DataSet: TDataSet);
  28.     procedure Table1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
  29.   public
  30.     Max: Integer;
  31.     procedure ComputeMax;
  32.     procedure ChooseRange;
  33.   end;
  34.  
  35. var
  36.   DataModule2: TDataModule2;
  37.  
  38. implementation
  39.  
  40. uses RangeDb;
  41.  
  42. {$R *.DFM}
  43.  
  44. procedure TDataModule2.ComputeMax;
  45. var
  46.   Bookmark: TBookmark;
  47. begin
  48.   // save a bookmark
  49.   Bookmark := Table1.GetBookmark;
  50.   try
  51.     Table1.DisableControls;
  52.     Max := 0;
  53.     try
  54.       Table1.First;
  55.       while not Table1.EOF do
  56.       begin
  57.         if Table1CustNo.AsInteger > Max then
  58.           Max := Table1CustNo.AsInteger;
  59.         Table1.Next;
  60.       end;
  61.     finally
  62.       Table1.EnableControls;
  63.     end;
  64.   finally
  65.     // return to the bookmark
  66.     Table1.GotoBookmark (Bookmark);
  67.     Table1.FreeBookmark (Bookmark);
  68.   end;
  69. end;
  70.  
  71. procedure TDataModule2.Table1NewRecord(DataSet: TDataSet);
  72. begin
  73.   Table1CustNo.Value := Max + 1;
  74. end;
  75.  
  76. procedure TDataModule2.Table1BeforeInsert(DataSet: TDataSet);
  77. begin
  78.   ComputeMax;
  79. end;
  80.  
  81. procedure TDataModule2.ChooseRange;
  82. begin
  83.   FormRange.Show;
  84. end;
  85.  
  86. procedure TDataModule2.Table1FilterRecord(
  87.   DataSet: TDataSet;
  88.   var Accept: Boolean);
  89. begin
  90. {  if (Table1Country.Value = 'US') or
  91.       (Table1Country.Value = 'US Virgin Islands') or
  92.       (Table1State.Value = 'Jamaica') then
  93.     Accept := True
  94.   else
  95.     Accept := False; }
  96.  
  97.   {if the item corresponding to the country in the
  98.   listbox is active, then view record}
  99.   with FormRange.ListBoxCountries do
  100.     Accept := Selected [Items.IndexOf (Table1Country.AsString)];
  101.   with FormRange.ListBoxStates do
  102.     if Selected [Items.IndexOf (Table1State.AsString)] then
  103.       Accept := True;
  104. end;
  105.  
  106. end.
  107.